import Vue from 'vue'
/*
*  验证表单
*  @param { Array }
* */
class Checker {
  constructor () {

  }
  add () {

  }
}
function checker(...rules) {
  return rules.every((arr) => {
    if (!(arr instanceof Array)) return true
    const [value, ...funs] = arr
    return funs.every(fun => {
      const result = fun(value)
      if (result === true) {
        return true
      }

      Vue.$vux.alert.show({
        title: '温馨提示',
        content: result
      })
      return false
    })
  })
}
export default checker

export const required = function (msg) {
  return function (v) {
    if (v === '' || v === null || v === undefined) {
      return msg
    }
    return true
  }
}

export const phone = function (msg = '请输入正确的手机号') {
  return function (v) {
    if (/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(v)) {
      return true
    }
    return msg
  }
}
